<?php
class travel{
	/*取旅游路线列表*/
	public function getTravelList(){
		$t=new db_recordset(NULL,"zyw_travel_line");
		$sql="select * from zyw_travel_line order by level";
		$t->query($sql,-1);
		$traveList=$t->getRecords();
		return $traveList;
	}

	/*取地区,取县，市，国外信息信息*/
	public function getRegionByLevel(){
		$t=new db_recordset(NULL,"zyw_scenic_region");
		$sql="select * from zyw_scenic_region where rlevel=0 or rlevel=1 or rlevel=4";
		$t->query($sql,-1);
		$rl=$t->getRecords();
		return $rl;
	}
	/*添加旅游线路*/
	public function addTravelLine($paramArr){
		$t=new db_table(NULL,"zyw_travel_line");
		$t->insert();
		$t->name=$paramArr['name'];
		$t->traveltool=$paramArr['traveltool'];
		$t->days=$paramArr['days'];
		$t->travelmemo=$paramArr['travelmemo'];
		$t->booknotes=$paramArr['booknotes'];
		$t->linememo=$paramArr['linememo'];
		$t->memodetail=$paramArr['memodetail'];
		$t->level=$paramArr['level'];
		$t->type=$paramArr['type'];
		$t->season=$paramArr['season'];
		$t->pricetype=$paramArr['pricetype'];
		$t->price=$paramArr['price'];
		$t->realprice=$paramArr['realprice'];
		$t->state=0;
		$t->create_date=date("Y-m-d");
		$t->update_date=date("Y-m-d");
		$t->pv=0;
		$t->post();
		$tvid=$t->tvid;
		$ret=$this->addDest2Dest($tvid,$paramArr);
		return $ret;
	}
	private function addDest2Dest($tvid,$paramArr){
		$t=new db_table(NULL,"zyw_travel_line_sites");
		$t->insert();
		$t->tvid=$tvid;
		$t->departure=$paramArr['departure'];
		$t->destination=$paramArr['destination'];

		$t->post();
		return true;
	}
	private function editDest2Dest($tvid,$paramArr){
		$t=new db_table(NULL,"zyw_travel_line_sites");
		$t->locate($tvid,-1);
		if($t->record_count()!=1)	return false;
		$t->departure=$paramArr['departure'];
		$t->destination=$paramArr['destination'];

		$t->post();
		return true;
	}
	/*取旅游线路详情*/
	public function getTravelDetail($tvid){
		$t=new db_recordset(NULL,"zyw_travel_line");
		$sql="select * from zyw_travel_line where tvid=$tvid";
		$t->query($sql,-1);
		$travelDetail=$t->getRecords();
		return $travelDetail[0];
	}
	/*取出发地*/
	public function getDepaSites($tvid){
		$t=new db_recordset(NULL,"zyw_travel_line_sites");
		$sql="select a . * from zyw_travel_line_sites a, zyw_scenic_region b	where a.departure = b.rid	and a.tvid =$tvid";
		$t->query($sql,-1);
		$depasite=$t->getRecords();
		return $depasite[0];
	}
	/*取目的地*/
	public function getDestSites($tvid){
		$t=new db_recordset(NULL,"zyw_travel_line_sites");
		$sql="select a . *  from zyw_travel_line_sites a, zyw_scenic_region b	where a.destination  = b.rid	and a.tvid =$tvid";
		$t->query($sql,-1);
		$destsite=$t->getRecords();
		debug::output(1,$destsite);
		return $destsite[0];
	}
	/*修改旅游线路*/
	public function doeditTravelLine($tvid,$paramArr){
		$t=new db_table(NULL,"zyw_travel_line");
		$t->locate($tvid,-1);
		if($t->record_count()!=1)	return false;
		$t->name=$paramArr['name'];
		$t->traveltool=$paramArr['traveltool'];
		$t->days=$paramArr['days'];
		$t->travelmemo=$paramArr['travelmemo'];
		$t->booknotes=$paramArr['booknotes'];
		$t->linememo=$paramArr['linememo'];
		$t->memodetail=$paramArr['memodetail'];
		$t->level=$paramArr['level'];
		$t->type=$paramArr['type'];
		$t->season=$paramArr['season'];
		$t->pricetype=$paramArr['pricetype'];
		$t->price=$paramArr['price'];
		$t->realprice=$paramArr['realprice'];
		$t->update_date=date("Y-m-d");
		$t->post();
		$ret=$this->editDest2Dest($tvid,$paramArr);
		return true;
	}
	/*删除旅游线路*/
	public function delTravel($tvid){
		$t=new db_recordset(NULL,"zyw_travel_line");
		$sql0="delete from zyw_travel_line where tvid=$tvid";

		$t->exec($sql0,-1);
		$t0=new db_recordset(NULL,"zyw_travel_line_sites");
		$sql2="delete from zyw_travel_line_sites where tvid=$tvid";
		$t0->exec($sql2,-1);
		$t1=new db_recordset(NULL,"zyw_travel_items");
		$sql3="delete from zyw_travel_items where tvid=$tvid";
		$t1->exec($sql3,-1);
		return true;
	}
	/*取出线路项目*/
	public function getAllItems($tvid){
		$t=new db_recordset(NULL,"zyw_travel_items");
		$sql="select a.*,b.name from zyw_travel_items a,zyw_travel_line b where a.tvid=b.tvid and a.tvid=$tvid";
		$t->query($sql,-1);
		$itemList=$t->getRecords();
		return $itemList;
	}
	/*添加路线项目*/
	public function addItems($tvid,$paramArr){
		$t=new db_table(NULL,"zyw_travel_items");
		$t->insert();
		$t->tvid=$tvid;
		$t->itemname=$paramArr['itemname'];
		$t->price=$paramArr['price'];
		$t->type=$paramArr['type'];
		$t->memo=$paramArr['memo'];
		$t->post();
		return true;
	}
	/*删除项目*/
	public function delItem($itemid){
		$t=new db_recordset(NULL,"zyw_travel_items");
		$sql="delete from zyw_travel_items where itemid=$itemid";
		$t->exec($sql,-1);
		return true;
	}
	/*取项目信息*/
	public function getItem($itemid){
		$t=new db_recordset(NULL,"zyw_travel_items");
		$sql="select * from zyw_travel_items where itemid=$itemid";
		$t->query($sql,-1);
		$item=$t->getRecords();
		return $item[0];
	}
	/*修改项目*/
	public function editItem($itemid,$paramArr){
		$t=new db_table(NULL,"zyw_travel_items");
		$t->locate($itemid,-1);
		if($t->record_count()!=1)	return false;
		$t->itemname=$paramArr['itemname'];
		$t->price=$paramArr['price'];
		$t->type=$paramArr['type'];
		$t->memo=$paramArr['memo'];
		$t->post();
		return true;
	}
	/*取线路日程*/
	public function getScheduleList(){
		$t=new db_recordset(NULL,"zyw_travel_schedule");
		$sql="select a.*,b.name from zyw_travel_schedule a,zyw_travel_line b where a.tvid=b.tvid order by schorder";
		$t->query($sql,-1);
		$schlist=$t->getRecords();
		return $schlist;
	}
	
	/*添加日程*/
	public function addSchedule($paramArr){
		$t=new db_table(NULL,"zyw_travel_schedule");
		$t->insert();
		$t->schedule=$paramArr['schedule'];
		$t->schdesc=$paramArr['scheduledesc'];
		$t->tvid=$paramArr['tvid'];
		$t->schorder=$paramArr['order'];
		$t->post();
		return true;
	}
	/*修改日程*/
	public function getSchById($id){
		$t=new db_recordset(NULL,"zyw_travel_schedule");
		$sql="select * from zyw_travel_schedule where id=$id";
		$t->query($sql,-1);
		$schedule=$t->getRecords();
		return $schedule[0];
	}
	public function editSchedule($id,$paramArr){
		$t=new db_table(NULL,"zyw_travel_schedule");
		$t->locate($id,-1);
		if($t->record_count()!=1)	return false;
		$t->schedule=$paramArr['schedule'];
		$t->schdesc=$paramArr['scheduledesc'];
		$t->schorder=$paramArr['order'];
		$t->post();
		return true;
	}
}
?>